package com.qi.controller;

import com.alibaba.fastjson.JSONObject;
import com.qi.pojo.Student;
import com.qi.service.BootService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;

/**
 * @author 姚炜琦
 * @Classname BootController
 * @Description TODO
 * @Date 2022/12/1 12:56
 */
@Log4j2
@RestController
@RequestMapping("/boot")
public class BootController {
    @Autowired
    private BootService bootService;

    @Autowired
    private HttpServletRequest request;

    @PostMapping("/selectStu")
    @ResponseBody
    public ArrayList<Student> selectStu(@RequestBody String name){
        log.info("功能名称：【{}】，请求地址：【{}】，请求方式：【{}】，请求参数：【{}】",
                "根据学生姓名查询学生信息",request.getRequestURI(),request.getMethod(), JSONObject.toJSON(name));

        ArrayList<Student> stuList = bootService.selectStu(name);

        log.info("功能名称：【{}】，请求地址：【{}】，请求方式：【{}】，响应结果：【{}】",
                "根据学生姓名查询学生信息",request.getRequestURI(),request.getMethod(), JSONObject.toJSON(stuList));

        return stuList;
    }

    @GetMapping("/selectAll")
    public ArrayList<Student> selectAll(){
        log.info("功能名称：【{}】，请求地址：【{}】，请求方式：【{}】，请求参数：【无】",
                "查询全部学生信息",request.getRequestURI(),request.getMethod());

        ArrayList<Student> listAll = bootService.selectAll();

        log.info("功能名称：【{}】，请求地址：【{}】，请求方式：【{}】，响应结果：【{}】",
                "查询全部学生信息",request.getRequestURI(),request.getMethod(), JSONObject.toJSON(listAll));

        return listAll;
    }
}
